﻿using System;
using System.Collections.Generic;
using System.Text;

/*
 * Author:Conis
 * Date:
 * Description:Xml的普通节点
 */

namespace Coins.Squirrel.Nodous.Xml
{
    public class XmlNodousNode: XmlNodousComponent, INodousNode
    {
        /// <summary>
        /// 创建普通节点
        /// </summary>
        /// <param name="name">节点的名称</param>
        protected internal XmlNodousNode(string name) : base(name, string.Empty) { }

        #region INodousNode 成员
        /// <summary>
        /// 创建数组节点
        /// </summary>
        /// <param name="name">节点的名称</param>
        /// <returns></returns>
        public INodousItem AddItem(string name)
        {
            XmlNodousItem item = new XmlNodousItem(name);
            this.list.Add(item);
            item.Parent = this;
            return item;

        }
        /// <summary>
        /// 创建普通节点
        /// </summary>
        /// <param name="name">节点的名称</param>
        /// <returns></returns>
        public INodousNode AddNode(string name)
        {
            XmlNodousNode node = new XmlNodousNode(name);
            this.list.Add(node);
            return node;
        }

        /// <summary>
        /// 创建叶子节点
        /// </summary>
        /// <param name="name">节点的名称</param>
        /// <param name="value">节点的值</param>
        /// <returns></returns>
        public INodousLeaf AddLeaf(string name, string value)
        {
            XmlNodousLeaf leaf = new XmlNodousLeaf(name, value);
            this.list.Add(leaf);
            return leaf;
        }

        /// <summary>
        /// 创建一个完全的叶子节点，需要保证值不包含Xml敏感字符，节点将以属性的方式保存
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public INodousLeaf SafeAddLeaf(string name, string value)
        {
            XmlNodousLeaf leaf = new XmlNodousLeaf(name, value, true);
            this.list.Add(leaf);
            return leaf;
        }

        #endregion
    }
}
